//对象兼容
class A1 {
  x = 1
  y = 2
}
class B1 {
  x = 3
  y = 4
  z = 5
}
let ab1: A1 = new A1()
let ab2: A1 = new B1()
// let ab2: B1 = new A1()
console.log(ab1);
console.log(ab2);
//接口兼容
interface IA {
  x: number
  y: number
}
interface IB {
  x: number
  y: number
  z: number
}
let ab3: IA = {
  x: 1,
  y: 2
}
// let ab4: IB = ab3//少给多报错
console.log(ab3);

//函数兼容
//参数个数不同
type F1 = (a: IA) => string
type F2 = (a: IB) => string
let f1: F1 = (a: IA) => {
  console.log('函数f1');
  console.log(a);
  return 'aaa'
}
let f2: F2 = (a: IB) => {
  console.log('函数f2');

  console.log(a);
  return 'bbbb'
}
f1({ x: 1, y: 2 })
f2 = f1
f2({ x: 7, y: 8, z: 9 })
console.log('f1f1f1f1f1f1f1f1f1');
console.log(f1);
console.log('f2f2f2f2f2f2f2f2f2');
console.log(f2);
//函数返回值个数不同
type F3 = () => { name: string }
type F4 = () => { name: string, age: number }
let f3: F3 = () => {
  return { name: 'f3f3f3f3' }
}
let f4: F4 = () => {
  return { name: 'f4f44ff4', age: 12 }
}
f3 = f4
// f4=f3//报错
console.log(f3());
console.log(f4());
